import React from 'react';
import { dictionaryList } from '@/services/dictionary';

const useDict = query => {
    const [data, setData] = React.useState([]);
    const [loading, setLoading] = React.useState(true);

    const fetchData = async () => {
        setLoading(true);
        const response = await dictionaryList(query);
        if (response && response.code === 10000) {
            setData(response.data);
        }
        setLoading(false);
    };

    React.useEffect(() => {
        fetchData();
    }, [JSON.stringify(query)]);

    return [loading, data];
};

export default useDict;
